<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>个人信息修改</title>
    <script src="/js/global.js"></script>
    <link rel="stylesheet" href="/css/font.css" type="text/css"/>
    <link rel="stylesheet" href="/css/layui.css" type="text/css"/>
    <link rel="stylesheet" href="/css/xadmin.css" type="text/css"/>
    <script type="text/javascript" src="/js/layui.js"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <script type="text/javascript" src="/js/jquery-3.5.1.min.js"></script>
</head>
<body>
<form class="layui-form" action="" style="margin-top: 50px;">
    <input type="text" name="userid" id="userid" style="display: none" required autocomplete="off" class="layui-input">

    <div class="layui-form-item">
        <label class="layui-form-label">账号</label>
        <div class="layui-input-block">
            <input type="text" name="account" id="account" disabled autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="text" name="password" id="password" required autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="realname" id="realname" required autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="email" name="email" id="email" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-block">
            <input type="tel" name="phone" id="phone" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">地址</label>
        <div class="layui-input-block">
            <input type="text" name="address" id="address" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">介绍</label>
        <div class="layui-input-inline">
            <textarea name="synopsis" class="layui-textarea" id="synopsis" cols="100" rows="5"></textarea>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">修改</button>
        </div>
    </div>
</form>
<script>
    layui.use(['layer', 'table', 'form', 'transfer', 'util', 'laydate'], function () {
        var table = layui.table;
        var $ = layui.jquery;
        var form = layui.form;
        var transfer = layui.transfer;
        var util = layui.util;
        var laydate = layui.laydate;


        //提交事件
        form.on('submit(demo1)', function (data) {
            $.post('./users/edit', data.field, function (res) {
                if (res.code === 200) {
                    globalData.setUserName(data.field.realname)
                    layer.msg(res.msg, {
                        icon: 1,
                        time: 2000
                    }, function () {
                        parent.location.reload();
                    });
                } else {
                    layer.msg(res.msg, {
                        icon: 5,
                        time: 2000
                    });
                }
            })
            return false;
        });

        initPersion();

        function initPersion() {
            let id = globalData.getUid();
            $.get('./users/getById', {id}, function (res) {
                if (res.code === 200) {
                    let data = res.data;
                    $("#account").val(data.account);
                    $("#password").val(data.password);
                    $("#realname").val(data.realname);
                    $("#email").val(data.email);
                    $("#phone").val(data.phone);
                    $("#address").val(data.address);
                    $("#userid").val(data.userid);
                    $("#synopsis").val(data.synopsis);
                } else {
                    layer.msg('网络繁忙，请稍后再试。', {
                        icon: 5,
                        time: 2000
                    });
                }
            })
        }
    });
</script>
</body>
</html>
